package com.industry.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.industry.framework.common.page.PageConverter;
import com.industry.framework.common.page.PageQuery;
import com.industry.framework.common.page.TableDataInfo;
import com.industry.system.controller.vo.SystemCodeVo;
import com.industry.system.dal.dataobject.SystemCode;
import com.industry.system.dal.db.SystemCodeMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author nbZhuozh
 * @Date 2025-02-14  11:39
 **/
@Service
public class SystemCodeService {

    @Resource
    private SystemCodeMapper systemCodeMapper;

    //获取系统码表所有数据
    public TableDataInfo<SystemCodeVo> getAllSystemCodes(PageQuery pageQuery){
        Page<SystemCode> systemCodePage = systemCodeMapper.selectPage(pageQuery.build(), new QueryWrapper<>());
        return TableDataInfo.build(PageConverter.convert(systemCodePage, SystemCodeVo.class));
    }

    public SystemCode querySystemCodeById(String codeId){
        if(null != codeId){
            return systemCodeMapper.selectById(Long.valueOf(codeId));
        }
        return new SystemCode();
    }

    public List<SystemCode> queryAllSystemCode(){
        return systemCodeMapper.selectList(new QueryWrapper<>());
    }


    @Transactional(rollbackFor = Exception.class)
    public int insert(SystemCode systemCode){
        systemCode.setTenantId("1");
        return systemCodeMapper.insert(systemCode);
    }

    @Transactional(rollbackFor = Exception.class)
    public int modify(SystemCode systemCode){
        return systemCodeMapper.updateById(systemCode);
    }

}
